<?php
session_save_path('sessions');
session_start();

// Connect to our database
include("include/dbconnection.php");

// Include our user class
include_once("include/user.php");


if($pricemin >= $pricemax)
{
  echo "Price range is incorrect!";
}
else if($sizemin >= $sizemax)
{
  echo "Size range is incorrect!";
}
else if($yearmin >= $yearmax)
{
  echo "Year built range is incorrect!";
}
else
{
$db_query = "SELECT 
    h.$TABLE_HOME_HOMEID, h.$TABLE_HOME_ADDRESS, h.$TABLE_HOME_STREETNAME, 
    h.$TABLE_HOME_CITY, h.$TABLE_HOME_COUNTRY, h.$TABLE_HOME_DISTRICT, h.$TABLE_HOME_ZONE,
	h.$TABLE_HOME_POSTALCODE, h.$TABLE_HOME_LOTSIZE, h.$TABLE_HOME_PROPERTYTYPE, h.$TABLE_HOME_YEARBUILT,
	h.$TABLE_HOME_HEATING, h.$TABLE_HOME_COOLING, h.$TABLE_HOME_PARKING, h.$TABLE_HOME_GARAGE,
	h.$TABLE_HOME_DRIVEWAY, h.$TABLE_HOME_NEIGHBOURHOOD, h.$TABLE_HOME_IMPROVEMENTS, h.$TABLE_HOME_EVALUATION,
	h.$TABLE_HOME_TAXES, h.$TABLE_HOME_UTILITYCOST, h.$TABLE_HOME_PRICE, h.$TABLE_HOME_COMMENTS,
	h.$TABLE_HOME_LISTINGDATE
    FROM $TABLE_HOME h 
    WHERE        city='".$city."' AND 
	 postalCode='".$postalcode."' AND
	 neighbourhood='".$neighbourhood."' AND
	 country='".$country."' AND
	 price>'".$pricemin."' AND
	 price<'".$pricemax."' AND
	 sizemin>'".$sizemin."' AND
	 sizemax<'".$sizemax."' AND
	 yearmin>'".$yearmin."' AND
	 yearmax<'".$yearmax."' OR (
	 propertytype1='".$propertytype1."' OR
	 propertytype2='".$propertytype2."' OR
	 propertytype3='".$propertytype3."' OR
	 propertytype4='".$propertytype4."' OR
	 heating='".$heating."' OR
	 cooling='".$cooling."' OR
	 garage='".$garage."' OR
	 driveway='".$driveway."')";
}
    
$resultSet = mysql_query($db_query);

if(mysql_num_rows($resultSet) == 0)
{
  echo "No matches found!";
}
else{ ?>
        <table>
        <?php
        // Show all the users and add an activation link.
        while( $result = mysql_fetch_array($resultSet) ) {
            ?>
            <b><tr><td><?php echo $result['$TABLE_HOME_HOMEID']?></td></tr></b>
			<br>
			<tr><td><b>Address:</b></td></tr>
			<br>
			<tr><td><?php echo $result['$TABLE_HOME_ADDRESS']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_STREETNAME']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_CITY']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_COUNTRY']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_DISTRICT']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_ZONE']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_POSTALCODE']?></td></tr>
			<br>
			<tr>
				<td><b>Size:</b></td>
				<td><?php echo $result['$TABLE_HOME_LOTSIZE']?></td>
			</tr>
			<br>
			<tr>
				<td><b>Property Type:</b></td>
				<td><?php echo $result['$TABLE_HOME_PROPERTYTYPE']?></td>
			</tr>
			<br>
			<tr>
				<td><b>Year built:</b></td>
				<td><?php echo $result['$TABLE_HOME_YEARBUILT']?></td>
			</tr>
			<br>
			<tr><td><?php echo $result['$TABLE_HOME_HEATING']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_COOLING']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_PARKING']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_DRIVEWAY']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_NEIGHBOURHOOD']?></td></tr>
			<tr><td><?php echo $result['$TABLE_HOME_IMPROVEMENTS']?></td></tr>
			<tr>
				<td><b>Evaluation:</b></td>
				<td><?php echo $result['$TABLE_HOME_EVALUATION']?></td>
			</tr>
			<br>
			<tr>
				<td><b>Utility Cost:</b></td>
				<td><?php echo $result['$TABLE_HOME_UTILITYCOST']?></td>
			</tr>
			<br>
			<tr>
				<td><b>Price:</b></td>
				<td><?php echo $result['$TABLE_HOME_PRICE']?></td>
			</tr>
			<br>
			<tr><td><b>Comments:</b></td></tr>
			<br>
			<tr><td><?php echo $result['$TABLE_HOME_COMMENTS']?></td></tr>
			<br>
			<tr>
				<td><b>Posted:</b></td>
				<td><?php echo $result['$TABLE_HOME_LISTINGDATE']?></td>
            </tr>
            <?php
      }// End while loop ?>
        </table>
<?php
} // End else statement
    
    // Close the connection
    mysql_close();
?>

